package com.butioy.study.jersey.config;

import com.butioy.study.jersey.controller.LoginController;
import com.butioy.study.jersey.mapper.UserMapper;
import com.butioy.study.jersey.service.IUserService;
import com.butioy.study.jersey.service.impl.UserServiceImpl;
import com.butioy.study.jersey.utils.MybatisUtils;
import org.glassfish.hk2.utilities.binding.AbstractBinder;
import org.glassfish.jersey.server.ResourceConfig;
import org.glassfish.jersey.server.ServerProperties;

/**
 * @author yanglq
 * @since 3.0.0
 */
public class ApplicationConfiguration extends ResourceConfig {

    public ApplicationConfiguration() {
        packages("com.butioy.study.jersey");// Now you can expect validation errors to be sent to the client.
        property(ServerProperties.BV_SEND_ERROR_IN_RESPONSE, true);
        // @ValidateOnExecution annotations on subclasses won't cause errors.
        property(ServerProperties.BV_DISABLE_VALIDATE_ON_EXECUTABLE_OVERRIDE_CHECK, true);

        register(LoginController.class);
        register(new AbstractBinder() {
            @Override
            protected void configure() {
                bind(UserServiceImpl.class).to(IUserService.class);

                UserMapper userMapper = MybatisUtils.getSession().getMapper(UserMapper.class);
                bind(userMapper).to(UserMapper.class);
            }
        });
    }
}
